import Vue from 'vue'
import Router from 'vue-router'
const _import = require('./_import_' + process.env.NODE_ENV)

const Layout = r => require.ensure([], () => r(require('@/views/Main')));
const Login = r => require.ensure([], () => r(require('@/views/Login')));
const NotFound = r => require.ensure([], () => r(require('@/views/NotFound')));

/**
 * hidden: true                   控制当前路由是否在左侧菜单栏中显示
 * alwaysShow: true               如果是true 无论子菜单是一个还是多个都会一直显示一级菜单
 * redirect: noredirect           如果 `redirect:noredirect` 在面包屑中不会产生导航连接
 * name:'router-name'             如果name不存在，改层级的路由不会出现在面包屑导航中
 * meta : {
    roles: ['admin','editor']     页面权限控制
    title: 'title'               面包屑显示标题
    icon: 'svg-name'             左侧菜单 显示图标名字
    details: 'AccountList'       因为当前列表页面跟详情页面在同一级目录，通过详情页面的该属性==列表页面的name 做管理，实现面包屑的层级关系
  }
 **/
Vue.use(Router)

export const constantRouterMap = [{
  path: '/login',
  component: Login,
  name: 'Login',
  hidden: true
},
  {
    path: '/404',
    component: Layout,
    redirect: '/404/index',
    hidden: true,
    children: [{
      path: 'index',
      component: NotFound,
      name: '404',
    }]
  },
  {
    path: '',
    redirect: '/index/desktop',
    hidden: true
  },
  {
    path: '/index',
    component: Layout,
    redirect: '/index/desktop',
    children: [{
      path: 'desktop',
      component: _import('Index'),
      name: 'Index',
      meta: {
        title: '我的桌面',
        icon: 'table',
        keepAlive:true,
      }
    }]
  }
]


const router = new Router({
  routes: constantRouterMap,
  scrollBehavior: () => ({}),
})

export const asyncRouterMap = [
  {
  path: '/userManager',
  component: Layout,
  redirect: '/userManager/role',
  alwaysShow: true,
  meta: {
    title: '用户管理',
    icon: 'management',
  },
  children: [
    {
    path: 'role',
    component: _import('Role'),
    name: 'Role',
    meta: {
      title: '角色',
      roles:['role'],
    },
    },
    {
      path: 'user',
      component: _import('User'),
      name: 'User',
      meta: {
        title: '用户',
        roles:['user']
      },
    },
    {
      path: 'GrantPermissions',
      component: _import('GrantPermissions'),
      name: 'GrantPermissions',
      hidden: true,
      meta: {
        title: '分配权限',
        details:'Role',
      },
    },
    {
      path: 'AssignFields',
      component: _import('AssignFields'),
      name: 'AssignFields',
      hidden: true,
      meta: {
        title: '分配存取栏位',
        details:'Role',
      },
    },
  ]
},
  {
    path: '/leads',
    component: Layout,
    alwaysShow: true,
    redirect: '/leads/list',
    meta: {
      title: 'LEADS',
      icon: 'leads',
      keepAlive:true,
    },
    children: [
      {
      path: 'list',
      component: _import('LeadsList'),
      name: 'LeadsList',
      meta: {
        title: 'LEADS列表',
        roles:['lead'],
        keepAlive:true,
      },
      },
      {
        path: 'filterlist',
        component: _import('LeadsFilterList'),
        name: 'LeadsFilterList',
        meta: {
          title: 'LEADS过滤名单',
          roles:['lead_filter']
        },
      },
      {
        path: 'details/:id',
        component: _import('LeadDetails'),
        hidden: true,
        name:'LeadDetails',
        meta: {
          title: 'LEADS详情',
          details:'LeadsList',
        },
        children: [
          {
            path: 'leade',
            component: _import('LeadDetailsLeade'),
            name: 'LeadDetailsLeade',
          },
          {
            path: 'real',
            component: _import('LeadDetailsReal'),
            name: 'LeadDetailsReal',
          },
          {
            path: 'demo',
            component: _import('LeadDetailsDemo'),
            name: 'LeadDetailsDemo',
          },
          {
            path: 'live',
            component: _import('LeadDetailsLive'),
            name: 'LeadDetailsLive',
          },
          {
            path: 'statistics',
            component: _import('LeadDetailsStatistics'),
            name: 'LeadDetailsStatistics',
          },
          {
            path: 'followup',
            component: _import('LeadDetailsFollowUp'),
            name: 'LeadDetailsFollowUp',
          },
          {
            path: 'remarks',
            component: _import('LeadDetailsRemarks'),
            name: 'LeadDetailsRemarks',
          },
          {
            path: 'changelog',
            component: _import('LeadDetailsChangeLog'),
            name: 'LeadDetailsChangeLog',
          },
        ]
      }
    ]
  },
  {
    path: '/account',
    component: Layout,
    redirect: '/account/list',
    alwaysShow: true,
    meta: {
      title: '真实账号',
      icon: 'account',
    },
    children: [
      {
        path: 'list',
        component: _import('AccountList'),
        name: 'AccountList',
        meta: {
          title: '真实账号列表',
          roles:['realaccount'],
          keepAlive:true,
        },
      },
      {
        path: 'details/:id',
        component: _import('AccountDetails'),
        hidden: true,
        name: 'AccountDetails',
        meta: {
          title: '真实账号详情',
          details:'AccountList',
        },
        children: [
          {
            path: 'info',
            component: _import('AccountDetailsInfo'),
            name: 'AccountDetailsInfo',
          },
          {
            path: 'demo',
            component: _import('AccountDetailsDemo'),
            name: 'AccountDetailsDemo',
          },
          {
            path: 'followup',
            component: _import('AccountDetailsFollowUp'),
            name: 'AccountDetailsFollowUp',
          },
          {
            path: 'remarks',
            component: _import('AccountDetailsRemarks'),
            name: 'AccountDetailsRemarks',
          },
          {
            path: 'changelog',
            component: _import('AccountDetailsChangeLog'),
            name: 'AccountDetailsChangeLog',
          },
          {
            path: 'trade',
            component: _import('AccountDetailsTrade'),
            name: 'AccountDetailsTrade',
          },
          {
            path: 'live',
            component: _import('AccountDetailsLive'),
            name: 'AccountDetailsLive',
          },
          {
            path: 'statistics',
            component: _import('AccountDetailsStatistics'),
            name: 'AccountDetailsStatistics',
          },
        ]
      },
    ]
  },
  {
    path: '/followup',
    component: Layout,
    redirect: '/followup/list',
    alwaysShow: true,
    meta: {
      title: '跟进项',
      icon: 'follow',
      roles:['follow']
    },
    children:[
      {
        path: 'list',
        name: 'FollowUp',
        component: _import('FollowUp'),
        meta: {
          title: '跟进项列表',
          roles:['follow']
        },
      },
    ]
  },
  {
    path: '/label',
    component: Layout,
    redirect: '/label/list',
    children: [{
      path: 'list',
      component: _import('Label'),
      name: 'LabelList',
      meta: {
        title: '标记',
        icon: 'pin',
        roles:['label']
      },
    }]
  },
  {
    path: '/telesys',
    component: Layout,
    redirect: '/telesys/list',
    children: [{
      path: 'list',
      component: _import('TeleSys'),
      name: 'telesysList',
      meta: {
        title: '呼叫系统',
        icon: 'pin',
        roles:['label']
      },
    }]
  },
  {
    path: '*',
    redirect:'/404',
    hidden: true
  },
]
export default router
